package com.it.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.it.dao.BrandDao;
import com.it.domain.Brand;
import com.it.service.BrandService;


import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * 业务层实现类
 */

@Service //业务层bean 交给IOC容器处理
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandDao brandDao; //装配数据层接口


    @Override
    public Boolean add(Brand brand) {
        return brandDao.insert(brand)>0;//判断影响数行数
    }

    @Override
    public Boolean delete(Integer id) {
        return brandDao.deleteById(id)>0;
    }

    @Override
    public Boolean update(Brand brand) {
        return brandDao.updateById(brand)>0;
    }

    @Override
    public Brand selectById(Integer id) {
        return brandDao.selectById(id);
    }

    @Override
    public List<Brand> selectAll() {
        return brandDao.selectList(null);
    }

    @Override
    public IPage<Brand> selectPage(int currentPage, int pageSize, Brand brand) {
        LambdaQueryWrapper<Brand> lqw=new LambdaQueryWrapper<>();
        lqw.like(brand.getStatus()!=null,Brand::getStatus,brand.getStatus());
        lqw.like(StringUtils.isNotBlank(brand.getBrandName()),Brand::getBrandName,brand.getBrandName());

        lqw.like(StringUtils.isNotBlank(brand.getCompanyName()),Brand::getCompanyName,brand.getCompanyName());
        IPage<Brand> page= new Page<>(currentPage,pageSize);
        return brandDao.selectPage(page,lqw);
    }

    @Override
    public IPage<Brand> selectPage(int currentPage, int pageSize) {
        IPage<Brand> page= new Page<>(currentPage,pageSize);
        return brandDao.selectPage(page,null);
    }



}
